package com.zfj.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfj.entity.Admin;
import com.zfj.mapper.AdminMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zfj
 * @date 2022/6/27 -20:37
 */
@Slf4j
@Service
public class AdminServiceImpl implements AdminService {
	@Autowired
	AdminMapper adminMapper;

	@Override
	public Admin login(String username, String password) {
//		Admin aaa = baseMapper.selectById(2);
		log.info("========================================");
		log.info("结果："+adminMapper.selectAll());
		log.info("========================================");
		Admin result=new Admin();
		try {
			Admin admin = adminMapper.selectByUsername(username);
			log.info("admin信息：{}",admin);
			if(admin!=null){
				if(admin.getPassword().equals(password)){
					BeanUtils.copyProperties(admin,result);
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<Admin> showAllAdmin() {
		return adminMapper.getAll("123456");
	}
}
